<?php
namespace App\Http\Controllers;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
use App\Services\ArticleService;

/**
 *
 * 文章管理控制器
 *
 * @author maqu
 *
 */
class ArticleController extends BaseController {

    //根据文章ＩＤ获取详情
    public function detail(ArticleService $articleService,$article_id){

        $result = $articleService->getDetailByArticleId($article_id);

        if(!$result['result']){
            return $this->failure($result['msg']) ;
        } else {
            return $this->success($result['data']);
        }
    }

    //根据文章ＣＯＤＥ获取详情
    public function detailByCode(ArticleService $articleService,$code){

        $result = $articleService->getDetailByArticleCode($code);

        if(!$result['result']){
            return $this->failure($result['msg']) ;
        } else {
            return $this->success($result['data']);
        }
    }
//
//	//帮助中心
//	public function helpcenter(){
//
//	    $result = array();
//
//	    $query = DB::table('acategory')->where('code',ACATEGORY_CODE_HELPCENTER)->get();
//
//	    if(!empty($query)){
//	        foreach ($query as $acategory){
//
//	            $temp =array('category_id'=>$acategory->cate_id,
//	                'category_name'=>$acategory->cate_name);
//
//	            $articles = DB::table('article')->where('cate_id',$acategory->cate_id)
//	            ->where('if_show',1)->where('store_id',0)->get();
//
//	            $temp['articles'] =array();
//
//	            if(!empty($articles))
//	            {
//	                foreach($articles as $article){
//	                    $temp['articles'][] = array('article_id'=>$article->article_id,
//	                       	'article_name'=>$article->title);
//	                }
//	            }
//
//	            $result[] = $temp;
//
//	        }
//	    }
//
//	    return $this->success($result,'成功');
//	}
//
//    //获取养生说的子分类
//    public function getYangshengCates(ArticleService $articleService){
//
//        $result = $articleService->convertCateCodetoCateId(ACATEGORY_CODE_YANGSHENG);
//        if(!$result['result']){
//            return $this->failure($result['msg']) ;
//        } else {
//            $cate_id = $result['data'];
//            $categorys= $articleService->getChildrenCategorys($cate_id);
//            return $this->success($categorys);
//        }
//
//    }

    //获取文章分类下的文章列表
    public function getArticlesByCateId(ArticleService $articleService,$cate_id,$firstrow=0,$pagesize=10){

        if(!$cate_id){
            return $this->args_invalid();
        }

        $articles = $articleService->getArticlesByCateId($cate_id,$firstrow,$pagesize);
        return $this->success($articles);
    }
}
